@layout("/common/default.html",{title:'添加',libs:['form']}){
<form class="layui-form"  lay-filter="layui-form-password" id="layui-form-password">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">修改密码</div>
                <div class="layui-card-body" pad15>

                    <div class="layui-form user-info-form" style="max-width: 400px;padding-top: 25px;">
                        <div class="layui-form-item">
                            <label class="layui-form-label">旧密码:<span style="color: red;">*</span></label>
                            <div class="layui-input-block">
                                <input type="password" id="password" name="password" class="layui-input"  lay-verify="password" required/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">新的密码:</label>
                            <div class="layui-input-block">
                                <input type="password" name="newPassword" id="LAY_password" lay-verify="pass" class="layui-input"  />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">确认密码:<span style="color: red;">*</span></label>
                            <div class="layui-input-block">
                                <input type="password" name="repassword"  lay-verify="repass" class="layui-input" required/>
                            </div>
                        </div>

                    </div>
                    <div class="form-group-bottom" style="z-index: 200" align="center">
                        <button class="layui-btn" lay-filter="pawssubmit" lay-submit>&emsp;提交&emsp;</button>
                        <button   id="btnclose" class="layui-btn layui-btn-primary"  >&emsp;取消&emsp;</button>
                    </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</form>

<script>
    layui.use([ 'form', 'upload', 'openLayer','resAjax'], function () {
        var  $ = layui.$,
            form=layui.form,
            openLayer=layui.openLayer,
            resAjax=layui.resAjax;


        $("#password").change(function(obj){
            var json={
                password:$("#password").val(),
            }

            var obj=resAjax.render({
                url:"/sys/user/verification", //url
                type:"post",//类型
                data:json,//id
            });
            if(obj.code!="0"){
                layer.msg("原密码错误!", {time: 2000, icon: 5});
            }else {
                openLayer.close();
            }
        });


        //自定义验证
        form.verify({
            //我们既支持上述函数式的方式，也支持下述数组的形式
            //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            //确认密码
            , repass: function (value) {
                if (value !== $('#LAY_password').val()) {
                    return '两次密码输入不一致';
                }
            }
        });

        form.on('submit(pawssubmit)', function (data) {
            var field=data.field;
            // 请求后台
            var obj=resAjax.render({
                url:'/sys/user/updatePassword', //url
                type:"post",//类型
                data:field
            });
            if (obj.cod=="1") {
                layer.msg("原密码错误!", {time: 2000, icon: 5});
            }
            else if (obj.cod=="0") {
                layer.msg("密码修改成功!", {time: 2000, icon: 6});
                openLayer.refresh();
            }
            else {
                layer.msg("未知错误!", {time: 2000, icon: 2});
            }

        });
    });
</script>

@}